using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Domain.Models.Mapping
{
    public class CourceMap : EntityTypeConfiguration<Cource>
    {
        public CourceMap()
        {
            // Primary Key
            this.HasKey(t => t.CourseID);

            // Properties
            this.Property(t => t.CourseID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Name)
                .IsFixedLength()
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Cources");
            this.Property(t => t.CourseID).HasColumnName("CourseID");
            this.Property(t => t.Name).HasColumnName("Name");

            // Relationships
            this.HasMany(t => t.Students)
                .WithMany(t => t.Cources)
                .Map(m =>
                    {
                        m.ToTable("StudentInCourse");
                        m.MapLeftKey("CourseID");
                        m.MapRightKey("StudentID");
                    });


        }
    }
}
